<?php
include_once( "./sql/sqlCon.php" );
include_once( "newsCMS/newsCMSConfigs.php" );

$refPage = "newsCMSDeleter.php";
include( "langincluder.php" );


if( !isset($_SESSION[$sessionUserLevelName]) || $_SESSION[$sessionUserLevelName]!=1 )
{
echo 'login fun';

}
else
{
	$logid = (int)$_GET['lid'];
	if( isset($_GET['action']) && $_GET['action']=="delete" )
	{
		$quer=mysql_query("SELECT line FROM $newsCMSTableName");
		$liner=mysql_num_rows($quer);

		mysql_query("DELETE FROM $newsCMSTableName WHERE line=$logid");

		for($i=$logid+1; $i<$liner; $i++) 
			mysql_query("UPDATE $newsCMSTableName SET line='".($i-1)."' WHERE line='$i'");

		if( !mysql_error() ) 
			echo $strings['successRedirecting'].'<script type="text/javascript">setTimeout(\'window.location = "./"\', 3000);</script>';
		else echo mysql_error();
	}
	else
	{
		$quer = mysql_query("SELECT * FROM $newsCMSTableName WHERE line = $logid");
		$result = mysql_fetch_array($quer);
		
		if( $result['line']!=$logid )
		{
			echo $strings['entryIDError']." ".$logid.'<br><button onclick="history.back()">'.$strings['goBack'].'</button>';
		}
		else
		{
			if( !empty($discussLinksArray[$i]) ) 
				$discussLink = "<a href='".$result['discussl']."'>".$strings['linkMoreInfoHere']."</a>";
			else $discussLink = $strings['noLink'] ;
	
			echo $strings['areYouSure']." ID $logid<br><br><br>";
		
			echo "<div class='entry'><span class='entryTitle'>".$result['title']."</span><span class='entryDate'>".$result['postedon']."</span>
				 <div class='entryContent'>".htmlspecialchars_decode($result['content'])."</div>
				 <div class='entryLink'>$discussLink</div></div>";
?>
<script type='text/javascript'>		
function deleteIt()
{
	var conf = confirm ("<?php echo $strings['confirm']; ?>");
	if( conf )
		document.forms["deleteForm"].submit();
}
</script>

<form id='deleteForm' method='post' action='index.php?p=603&lid=<?php echo $logid; ?>&action=delete'>
</form>
<br>
<div style="text-align: center">
<button type="button" onclick="deleteIt()"><?php echo $strings['submitButton']; ?></button>
</div>
<?php			
		}
	}
}
?>